<?php 
include("../lang/cn/company_type_config.php");
include_once("../module/micro_shop/includes/plugin_micro_shop_class.php");
include_once("../module/product/includes/plugin_order_class.php");
$order = new order();
$microShop = new MicroShop();

$de = array();
if($_GET['id']>0){
	//获取用户信息
	$sql = "select member_id from ".TARENTO." where id={$_GET['id']}";
	$db->query($sql);
	$memberId = $db->fetchField('member_id');
	$de = $microShop->get_tarento_detail($memberId);
	//获取用户返利结算记录信息
	$de['rebate_records'] = $microShop->get_tarento_rebate_records($memberId);
	//用户店铺信息
	$de['shop_info'] = $microShop->get_shop_info($memberId);
}
// else if($_GET['id'] == "tongji" && $_GET['sid']>0){
    
//     //获取用户信息
//     $sql = "select member_id from ".TARENTO." where id={$_GET['sid']} ";
//     $db->query($sql);
//     $memberId = $db->fetchField('member_id');
//     //查询统计信息
    
//     //NO.1    获取所有订单数据，支付完成的
//     $sql = "select ms_id,order_id,cost,cpns_price,order_time from ".ORDER." where status >= 2  and id > 1750 and id <= 2000 ";
//     $db->query($sql);
//     $orderInfos = $db->getRows();
    
//     foreach($orderInfos as $vos){
//         $cost = $vos['cost'] - $vos['cpns_price'];//参与销售额的金额
//         $flow_time_str = date('Ym',$vos['order_time']);
        
//         //更新自己
//         $sql = "select id from ".MICROSHOPSALESFLOW." where member_id={$vos['ms_id']} and flow_time_str='{$flow_time_str}' and status=0";
// 	    $db->query($sql);
// 	    $flowId = $db->fetchField('id');
	    
// 	    $group_sales = 0;
// 	    if($flowId>0){//已经有该月的数据则更新
// 	    	$sql = "update ".MICROSHOPSALESFLOW." set self_sales=self_sales+{$cost},group_sales=group_sales+{$group_sales} where id={$flowId}";
// 	    }else{//无则新增
// 	        $sql = "insert into ".MICROSHOPSALESFLOW." (`member_id`,`self_sales`,`group_sales`,`flow_time_str`,`status`) values('{$vos['ms_id']}','{$cost}',0,'{$flow_time_str}','0')";
// 	    }
// 	    $db->query($sql);
         
//         $sql = "select relations,level from ".TARENTO." where member_id={$vos['ms_id']}";
//         $db->query($sql);
//         $shopInfo = $db->fetchRow();
//         $relations = $shopInfo['relations'];
         
//         if($shopInfo['level']>1){//如果不是顶级则查找所有上级并更新他们的团队销售额
//             $othersMid = str_replace(','.$vos['ms_id'].',', '', $relations);
//             if(!empty($othersMid)){
//                 $members = explode(',', $othersMid);
//                 foreach ($members as $dos)
//                 {
//                     $sql = "select id from ".MICROSHOPSALESFLOW." where member_id={$dos} and flow_time_str='{$flow_time_str}' and status=0";
//                     $db->query($sql);
//                     $flowId = $db->fetchField('id');
//                     if($flowId>0){//已经有该月的数据则更新
//                         $sql = "update ".MICROSHOPSALESFLOW." set self_sales=self_sales+0,group_sales=group_sales+{$cost} where id={$flowId}";
//                     }else{//无则新增
//                         $sql = "insert into ".MICROSHOPSALESFLOW." (`member_id`,`self_sales`,`group_sales`,`flow_time_str`,`status`) values('{$dos}',0,'{$cost}','{$flow_time_str}','0')";
//                     }
//                     $db->query($sql);
//                 }
//             }
//         }
//     }
//     $de = $microShop->get_tarento_detail($memberId);
//     //用户店铺信息
//     $de['shop_info'] = $microShop->get_shop_info($memberId);
//     //获取用户返利结算记录信息
//     $de['rebate_records'] = $microShop->get_tarento_rebate_records($memberId);
// }
else{
	msg((empty($_SERVER['HTTP_REFERER'])?"{$config->site_index}admin":$_SERVER['HTTP_REFERER']));
}

$tpl->assign("de",$de);
$tpl->assign("config",$config);
$tpl->display("shop_detail.htm");
?>